package com.enjoyor.health.HGPT.core.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * 微信小程序配置项
 * @author Zhu Min
 * @date 2023/10/18 9:19
 */
@Data
@Configuration
public class WxAppConfig {

    @Value("${wx.app.id}")
    private String appId;

    @Value("${wx.app.secret}")
    private String appSecret;

    @Value("${wx.user.id.key}")
    private String userIdKey;

    @Value("${wx.token.key}")
    private String tokenKey;

    @Bean
    public WxMaService wxMaService(){
        WxMaService maService = new WxMaServiceImpl();
        WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();

        config.setAppid(this.appId);
        config.setSecret(this.appSecret);
        config.setToken(this.tokenKey);
        config.setAesKey(this.userIdKey);
        config.setMsgDataFormat("JSON");
        maService.setWxMaConfig(config);
        return maService;

    }

}
